<template>
  <div style="width: 100%;height:100%">
    <a-form-model
      ref="ruleForm"
      :model="newTaskData"
      class="AsteriskAfter newEditStyle rightDrawerWithoutCol"
    >
      <a-form-model-item :label="$t('是否上传OTA功能测试报告')" prop="taskGcyExt.uploadFunctionTestReport" required style="margin-bottom:0">
        <a-radio-group v-model="newTaskData.taskGcyExt['uploadFunctionTestReport']" 
        @change="$nextTick(()=>$refs.ruleForm.clearValidate(['taskGcyExt.' + newTaskData.taskGcyExt.reasonKey, 'taskGcyExt.' + newTaskData.taskGcyExt.key]))">
            <a-radio :key="newTaskData.taskGcyExt.boolKey + '1'" :value="true">
            {{ $t('yes') }}
            </a-radio>
            <a-radio :key="newTaskData.taskGcyExt.boolKey + '0'" :value="false">
            {{ $t('no') }}
            </a-radio>
        </a-radio-group>
      </a-form-model-item>
      <a-form-model-item prop="taskGcyExt.noFunctionReportReason" v-if="newTaskData.taskGcyExt['uploadFunctionTestReport'] === false"
                          :rules="[{required: true,message: '原因不能为空'}, {max:100, message: '长度不能超过100'}]">
      <custom-text-area
          @change="newTaskData.taskGcyExt['noFunctionReportReason'] = $event"
          :val="newTaskData.taskGcyExt['noFunctionReportReason']"
          :rows="2"
          :placeholder="$t('不上传'+ newTaskData.taskGcyExt.name +'原因')"
          :max-len="100"
      />
      </a-form-model-item>
      <a-form-model-item prop="taskGcyExt.functionTestReport" v-else
                          :rules="{required: true,message: '请上传文件', trigger: 'change'}">
        <FileUploader v-model="newTaskData.taskGcyExt['functionTestReport']" @change="newTaskData.taskGcyExt['functionTestReport'] = $event"/>
      </a-form-model-item>
    </a-form-model>
  </div>
</template>
<script>
import CustomTextArea from '@/components/CustomTextArea/index.vue'
import FileUploader from '@/components/Upload/FileUploader'
export default {
  components: {
    CustomTextArea,
    FileUploader
  },
  props:{
    auditInfo:{
      type:Object,
      default:{}
    }
  },
  computed: {},
  data () {
    return {
      newTaskData:{
        taskGcyExt:{
          functionTestReport:[],
          noFunctionReportReason:'',
          uploadFunctionTestReport:true,
          name : 'OTA功能测试报告',
          key: 'functionTestReport',
          boolKey: 'uploadFunctionTestReport',
          reasonKey: 'noFunctionReportReason'
        }
      }
    }
  },
  created () {},
  mounted () {},
  methods: {
    // 获取表单中的数据
    getFormData () {
      return new Promise((resolve, reject) => {
        const data = {
          auditInfo:this.auditInfo,
          testReport:this.newTaskData.taskGcyExt.functionTestReport.map(file => file.id),
          noReportReason:this.newTaskData.taskGcyExt.noFunctionReportReason,
          status:'PASS'
        }
        this.$refs.ruleForm.validate(valid => {
          if (!valid) {
            reject(valid)
            return
          }
          resolve(data)
        })
      })
    },
  }
}
</script>
<style lang="less" scoped>
</style>
